//
//  ChangeGroupNameViewController.m
//  huashiedu
//
//  Created by oceans on 2018/9/14.
//  Copyright © 2018年 hema. All rights reserved.
//

#import "ChangeGroupNameViewController.h"
#import "HttpRequest.h"

@interface ChangeGroupNameViewController ()

@property (weak, nonatomic) IBOutlet UITextField *textField;
@end

@implementation ChangeGroupNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViews];
    self.textField.text = self.model.name;
}

- (void)setupViews {
    self.navigationItem.title = @"群聊名称";
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(save)];
    [item setTitleTextAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:17.0], NSForegroundColorAttributeName: [UIColor colorWithRed:63/255.0 green:63/255.0 blue:63/255.0 alpha:1.0]} forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = item;
}

- (void)save {
    
    if (_textField.text.length > 0) {
        [_textField resignFirstResponder];
        NSString *name = _textField.text;
        __weak typeof(self) weakself = self;
        [HttpRequest postURL:kchange_group_name paras:@{@"group_id": _group_id, @"name": _textField.text} showProgress:YES successful:^(id  _Nullable result) {
            NSLog(@"%@", result);
            weakself.model.name = name;
            [weakself.navigationController popViewControllerAnimated:YES];
        } failed:nil];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
